<#include "/admin/inc/page.html">
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>草稿箱 - UnaBoot</title>
    <link rel="icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="${una}/ub-admin/img/favicon.png" type="image/x-icon">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/font-awesome.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/ionicons.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/adminlte.css">
    <link rel="stylesheet" href="${una}/ub-admin/css/unaboot-admin.css">
    <link rel="stylesheet" href="${una}/ub-admin/plugin/layer/skin/default/layer.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700">
</head>
<body class="sidebar-mini layout-fixed layout-navbar-fixed text-md <!--sidebar-collapse-->">
<div class="wrapper">
    <nav class="main-header navbar navbar-expand navbar-white navbar-light">
        <#include "/admin/inc/header.html">
    </nav>
    <aside class="main-sidebar sidebar-dark-primary ">
        <#include "/admin/inc/aside.html">
    </aside>
    <div class="content-wrapper bg-gray-custom">
        <div class="content-header pb-0">
            <div class="row mb-2">
                <div class="col-12">
                    <h4 class="ml-2 mb-0 text-dark">我的草稿箱 <a href="${una}/admin/posts/create" class="btn btn-sm btn-outline-primary">写文章</a></h4>
                </div>
            </div>
        </div>
        <div class="content">
            <div class="container-fluid">
                <div class="row text-sm mt-1">
                    <div class="col-12">
                        <table class="table post-datatable table-striped table-hover" style="border: 1px solid #ddd">
                            <thead>
                            <tr class="bg-white">
                                <td width="35%">标题</td><td width="10%">封面</td><td>作者</td><td>分类</td><td>标签</td><td>日期</td>
                            </tr>
                            </thead>
                            <tbody>
                            <#if data.content?? && data.content?size gt 0>
                                <#list data.content as post>
                                    <tr>
                                        <td>
                                            <span class="text-secondary">[草稿]</span>
                                            <#if post.source == 0>
                                                <span class="tag tag-blue">原创</span>
                                            </#if>
                                            <#if post.status == 1 || post.status == 2>
                                                <#if post.stick == true>
                                                    <span class="tag tag-red">置顶</span>
                                                </#if>
                                                <#if post.recommend == true>
                                                    <span class="tag tag-blue">推荐</span>
                                                </#if>
                                            </#if>
                                            <a href="javascript:void(0);">
                                                ${post.title}
                                            </a>
                                            <div class="row-actions">
                                                <#if post.status == -1>
                                                    <#if post.userId == profile.id>
                                                        <span class="edit">
                                                            <a href="${una}/admin/posts/${post.id}"><i class="fa fa-edit"></i>编辑</a> |
                                                        </span>
                                                        <span class="submit">
                                                            <a href="javascript:void(0);" aria-id="${post.id}"><i class="fa fa-send-o"></i>发布</a> |
                                                        </span>
                                                        <span class="trash">
                                                            <a href="javascript:void(0);" aria-id="${post.id}"><i class="fa fa-trash-o"></i>删除</a>
                                                        </span>
                                                    </#if>
                                                </#if>
                                            </div>
                                        </td>
                                        <td>
                                            <#if post.thumb?? && post.thumb != "">
                                                <img src="${post.thumb}" class="img-fluid post-thumb">
                                            <#else>
                                                <img src="${una}/ub-admin/img/thumb.jpg" class="img-fluid post-thumb">
                                            </#if>

                                        </td>
                                        <td>
                                            <a href="javascript:void(0)">
                                                <#if post.userId == profile.id>
                                                    我自己
                                                <#else>
                                                    ${post.author}
                                                </#if>
                                            </a>
                                        </td>
                                        <td>
                                            <#if post.category??>
                                                <span class="tag tag-red">${post.category.name}</span>
                                            <#else>
                                                <span class="tag tag-red">Uncategoried</span>
                                            </#if>
                                        </td>
                                        <td>
                                            <#if post.tags?? && post.tags?size gt 0>
                                                <#list post.tags as tag>
                                                    <span class="tag tag-blue">${tag.name}</span>
                                                </#list>
                                            </#if>
                                        </td>
                                        <td>
                                            <#if post.status == -1>
                                                创建于<br>
                                            <#elseif post.status == 0>
                                                审核中<br>
                                            <#else>
                                                已发布<br>
                                            </#if>
                                            <span class="post-time"><i class="fa fa-calendar-o"></i> ${post.createTime?string("yyyy-MM-dd HH:ss")}</span>
                                        </td>
                                    </tr>
                                </#list>
                            <#else>
                                <tr><td colspan="6" class="text-center">暂无任何文章</td></tr>
                            </#if>
                            </tbody>
                            <tfoot>
                            <tr class="bg-white">
                                <td width="35%">标题</td><td width="10%">封面</td><td>作者</td><td>分类</td><td>标签</td><td>日期</td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
                <!--分页按钮-->
                <div class="row text-sm mt-1">
                    <#if data?? && data.content?size gt 0 && data.totalPages gt 1>
                        <div class="col-12">
                            <nav aria-label="..." class="pull-right">
                                <@pagination una+"/admin/posts/draft" data 9/>
                            </nav>
                        </div>
                    </#if>
                </div>
            </div>
        </div>
    </div>
    <footer class="main-footer">
        <#include "/admin/inc/footer.html">
    </footer>
</div>
<script src="${una}/ub-admin/plugin/jquery/jquery.min.js" type="text/javascript"></script>
<script src="${una}/ub-admin/plugin/bootstrap/js/bootstrap.bundle.min.js" type="text/javascript"></script>
<script src="${una}/ub-admin/js/adminlte.js" type="text/javascript"></script>
<script src="${una}/ub-admin/plugin/layer/layer.js" type="text/javascript"></script>
<script src="${una}/ub-admin/js/unaboot-admin.core.js" type="text/javascript"></script>
<script type="text/javascript">
    $(".submit a").on("click",function(){
        var id = $(this).attr("aria-id");
        if(id == null || typeof(id) == 'undefined' ){
            return false;
        }else{
            layer.open({
                type:2,
                title:"<i class=\"fa fa-send-o\"></i> 发布文章",
                shadeClose:false,
                shade:0.4,
                offset:['55px'],
                area:['550px','500px'],
                content:'${una}/admin/posts/'+id+'/publish',
                resize:false,
                anim:1
            });
        }

    });
    /**
     * 删除文章
     */
    $(".trash a").on("click",function(){
        var id = $(this).attr("aria-id");
        if(id == null || typeof(id) == 'undefined' ){
            return false;
        }else{
            layer.alert("确定删除这篇文章吗？该操作不可逆",{
                title:"<i class='fa fa-info-circle'></i> 提示",
                icon:0,
                btn:['是(Y)','否(N)'],
                offset:['55px'],
                shadeClose: false,
                shade:[0.4,'#fff'],
                anim: 1
            },function(){
                var load = layer.load(2,{shade:[0.4,'#f0f0f0']});
                $.ajax({
                    type:'DELETE',
                    url:"${una}/admin/posts/"+id,
                    success:function(){
                        layer.close(load);
                        layer.alert("当前操作已成功执行!",{
                            title:"<i class='fa fa-info'></i> 提示",
                            icon:1,
                            shade:[0.4,"#fff"],
                            shadeClose:false,
                            time:0,
                            btn:['OK'],
                            yes:function(index){
                                layer.close(index);
                                window.location.href="${una}/admin/posts/?offset=${data.number+1}";
                            }
                        });
                    },
                    error:function(){
                        layer.close(load);
                        layer.alert("当前操作失败!请稍后再试。",{
                            title:"<i class='fa fa-info'></i> 提示",
                            icon:1,
                            shade:[0.4,"#fff"],
                            shadeClose:false,
                            time:0,
                            btn:['Close'],
                            yes:function(newIndex){
                                layer.close(newIndex);
                            }
                        });
                    }
                });
            },function(index){
                layer.close(index);
            });
        }
    });
</script>
</body>
</html>